package org.goyo.main.domain.dao.system.impl;

import java.util.ArrayList;
import java.util.List;

import org.goyo.main.domain.dao.BaseDAO;
import org.goyo.main.domain.dao.system.ISysUserMenuDao;
import org.goyo.main.domain.entity.system.SysMenu;
import org.goyo.main.domain.entity.system.SysUserMenu;
import org.springframework.stereotype.Repository;

@Repository
public class SysUserMenuDaoImpl extends BaseDAO implements ISysUserMenuDao{
	
	@Override
	public List<SysUserMenu> findByUserId(String userId) {
		String hql = "from SysUserMenu where userId = ?";
		return this.findObjects(hql, null, new Object[]{userId});
	}

	@Override
	public List<SysMenu> findByUserIdAndLevel(String userId, int level) {
		StringBuffer buf = new StringBuffer();
		List<Object> par = new ArrayList<Object>();
		buf.append("select a from SysMenu a , SysUserMenu b where a.uuid = b.menuId and a.level=? ");
		par.add(level);
		if(userId != null ){
			buf.append(" and b.userId=?");
			par.add(userId);
		}
		buf.append(" order by a.seq");
		return this.findObjects(buf.toString(), null, par.toArray());
	}

	@Override
	public List<SysMenu> findByLevel(int level) {
		StringBuffer buf = new StringBuffer();
		buf.append("select a from SysMenu a where a.level=?  order by a.seq");
		return this.findObjects(buf.toString(), null, new Object[]{level});
	}
}
